package com.springboot.dense.controller;

import com.springboot.dense.util.PythonUtil;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Controller
public class UpLoadCtrl {

    /**
     * 本地保存路径
     */
    @Value("${file.path}")
    private String dirPath;

    @Autowired
    private PythonUtil pythonUtil;

    @RequestMapping("/upload")
    @ResponseBody
    public JSONObject upload(MultipartFile file) throws IOException {
        InputStream inputStream = file.getInputStream();
        String fileName = file.getOriginalFilename();
        Files.copy(inputStream, new File(dirPath + fileName).toPath(), StandardCopyOption.REPLACE_EXISTING);
        System.out.println(dirPath+fileName);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", "1");
        jsonObject.put("mas", dirPath+fileName);
        return jsonObject;
    }

}
